def cal_next(S):
    temp=[]
    length=len(S)
    for i in range(length):
        temp[i]=S[0:i]
        pass
    for i in range(length):
